package com.usefullc.system.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.usefullc.system.domain.AppVersion;
import com.usefullc.system.entity.Pager;
import com.usefullc.system.entity.WebResult;
import com.usefullc.system.query.AppVersionQuery;
import com.usefullc.system.service.AppVersionService;
import com.usefullc.system.validator.UsefulValid;
import com.usefullc.system.vo.AppVersionVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(path = "/system/appVersion/")
@Api(tags="App版本")
public class AppVersionController {

    @Autowired
    private AppVersionService appVersionService;

    @Value("${usefullc.appEnv}")
    private String appEnv;

    @ApiOperationSupport(author = "Sampson@usefullc.com")
    @ApiOperation(value = "获取列表", response = WebResult.class)
    @GetMapping(path = "list", produces = "application/json")
    public WebResult list(AppVersionQuery query) {
        query.setOrderByColumn("versionNo");
        Pager<AppVersionVo> pager = appVersionService.findVoByPage(query);
        return WebResultBuilder.successResult(pager);
    }

    @ApiOperation(value = "检测是否有最新版本",response = WebResult.class)
    @GetMapping(path = "hasNewVersion",produces = "application/json")
    public Object hasNewVersion(@UsefulValid AppVersionQuery query) {
        AppVersion appVersion = appVersionService.hasNewVersion(query);
        return WebResultBuilder.successResult("有最新版本"+appVersion.getVersion(),appVersion);
    }

}
